<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>最佳合伙人</title>
<meta name="viewport" content="width=100%, initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/lib/weix/style/weui.min.css">
<link rel="stylesheet" href="/css/fonts.css">
<link rel="stylesheet" href="/css/comm.css">
<link rel="stylesheet" href="/css/sign.css">
</head>

<body>
<div class="bjs"></div>

<div class="dengl_box">
  <div class="tit_box">
  	<span class="qu"><i class="icon-user"></i></span>
  </div>
  <div class="bao_box">
    <form id="J_form" method="post">
      <input type="hidden"  id="J_id" value = "${id}">
      <div class="inp_box">
        <input class="txt" type="text" value="${username}" id="J_username" readonly />
      </div>
      <div class="inp_box">
        <input class="txt" type="tel" value="${phone}" id="J_phone" maxlength="11" readonly />
      </div>
      <div class="inp_box">
        <input class="txt" type="tel" placeholder="手机验证码" id="J_verify" />
        <a href="javascript:;" class="yzm on" id="J_getCode" data-num="0">获取</a>
      </div>
      <div class="inp_box">
        <input class="txt" type="text" value="${role_name}" id="J_ltd" readonly />
        <input type="hidden" id = "J_openid" value = "${openid}">
      </div>
      <a href="javascript:;" class="weui-btn weui-btn_primary" style="margin-top:25px;" id="J_submit">登&nbsp;&nbsp;录</a>
    </form>
  </div>
</div>

<div class="weui-footer weui-footer_fixed-bottom">
    <p class="weui-footer__text foot_logo"></p>
</div>
<script src="/js/zepto.min.js"></script>
<script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<script src="/js/comm.js"></script>
<script>
$(function(){
	tits() //标题
	//-----------------------------------------------------
	//发送验证码
	$(document).on('click', '#J_getCode', function(){
		var $this_t = $(this);
		var num = $this_t.attr('data-num')

		if(num == 1){
			weui.topTips('请等待300秒后再次发送短信！');
		}else if(num == 0){
			var phone = $('#J_phone').val();
			var url = "/login/send_code";
			var data = {phone:phone};
			$.ajax({
				type: "POST",
				dataType: 'json',
				async: false,
				contentType: "application/json; charset=utf-8",
				data: JSON.stringify(data),
				url: url,
				success: function(res){
					if(res.code == 10002){
							weui.toast('发送成功！', 1000);
							$this_t.attr('data-num',1)
							var num_js = 0;
							var time = 60*5;
							for (var i=1;i<time+1;i++)
							{
								setTimeout(function(){
									num_js++;
									$this_t.html(time-num_js+'s后重试');
									if(num_js == time){
										setTimeout(function(){
											$this_t.html('获取')
											$this_t.attr('data-num',0)
										},1000);
									}
								},1000*i);
							}

					}else if(res.code == '-100033'){
						weui.topTips('5分钟只能发送一次验证码，请稍后再试！', 1000);
					}else{
						weui.topTips('发送失败，请稍后再试！');
					}
				},
				error: function(e){
					weui.toast('发送失败，请重新发送！', 1000);
				},
				complete: function(e){
				}
			});
		}
	});
	//-----------------------------------------------------
	//提交操作
	$(document).on('click','#J_submit',function(){
		var name_data = $('#J_username').val().trim();
		var tel_data = $('#J_phone').val().trim();
		var cod_data = $('#J_verify').val().trim();
		var ltd_data = $('#J_ltd').val().trim();

		if(name_data.trim() == ''){
			weui.topTips('请填写您的姓名');
			return false
		}

		if(!tel(tel_data)){
			return false
		}

		if(cod_data == ''){
			weui.topTips('请填写手机验证码');
			return false
		}


		if(ltd_data == ''){
			weui.topTips('请填写类型');
			return false
		}

		var loading = weui.loading('登录中', {
			className: 'custom-classname'
		});

		setTimeout(function () {
			var data = {id:$("#J_id").val(),username:$("#J_username").val(),phone:$("#J_phone").val(),verify_code:$("#J_verify").val(),openid:$("#J_openid").val()};
			var url = "/login/login";
			$.ajax({
				type: "POST",
				dataType: 'json',
				async: false,
				contentType: "application/json; charset=utf-8",
				data: JSON.stringify(data),
				url: url,
				success: function(res){
					if(res.code == "200"){
						loading.hide();
						weui.toast('登录成功', {
							duration: 1000,
							className: 'custom-classname',
							callback: function(){
								location.replace('/userPage/usercenter')
							}
						});
					}else{
						loading.hide();
						weui.topTips(res.msg, 1000);
					}
				},
				error: function(){

				},
				complete: function(){
				}
			});
		}, 500);


	})
});
</script>
</body>
</html>
